/**
 * Created by jt on 2017/5/8.
 */
import "./index.less";
import "../../../unit/common/js/bootstrap_js/select2.min.js";
import "../../../unit/common/js/bootstrap_js/jquery.dataTables.js";
import "../../../unit/common/js/bootstrap_js/form-samples.js";

import proInfoTpl from "./proInfo.handlebars";
import setTableTpl from "./set_table.handlebars";
import {currTyp,dpstFlg,pubPriFlg} from "../config.js";
App.init();

var token = sessionStorage.getItem('token');
if (token == null || token =='') {
    location.href = HOST_FRT+'/logins/login.html';
}

jQuery('.logOut').attr('href','../logins/login.html');
var projId = getArgs().id;

$.ajax({
    url: HOST_ADDR + '/cpmp/bidProjOff/viewProjRstDtl/'+projId,
    type: 'get',
    dataType: 'json',
    headers: {
        'access_token': token,'login_type':'ums'
    },
    contentType: "application/json",
    success: function(resp){
        if (!resp.success) {
            alert(resp.msgCod+' '+resp.msgInf);
            return;
        }
        console.log(resp);

        //处理数据
        resp.data.bidProjOff.projNbrFmt = resp.data.bidProjOff.projNbr || '';
        resp.data.bidProjOff.bidOpenTimFmt = (new Date(resp.data.bidProjOff.bidOpenTim)).Format("yyyy-MM-dd hh:mm:ss") || '';
        resp.data.bidProjOff.bidEndTimFmt = (new Date(resp.data.bidProjOff.bidEndTim)).Format("yyyy-MM-dd hh:mm:ss") || '';
        resp.data.bidProjOff.currTypFmt = currTyp[resp.data.bidProjOff.currTyp] || '';
        resp.data.bidProjOff.dpstFlgFmt = dpstFlg[resp.data.bidProjOff.dpstFlg] || '';
        resp.data.bidProjOff.pubPriFlgFmt = pubPriFlg[resp.data.bidProjOff.pubPriFlg] || '';

        if(resp.data.matTypDesc!=null && resp.data.matTypDesc!=''){
            resp.data.bidProjOff.matTyp = resp.data.matTypDesc;
        }

        let tableHtml = setTableTpl(resp.data.bidProjOff);
        jQuery('.basicInfo').append(tableHtml);
        jQuery('.bidBok').html(resp.data.bidProjOff.bidBok);

        let resultHtml = proInfoTpl({bidResult: resp.data.bidProjOffSplrRstLists});
        $('.bidResult').append(resultHtml);

    },
    error:function(err){
        console.log(err);
    }
});